<template>
	<el-card>
		<el-space>
			<el-space>
				<el-button icon="Plus" type="primary" @click="updatePermHandle(true, null)">新增</el-button>
			</el-space>
		</el-space>

		<el-table v-loading="state.dataListLoading" :data="dataList" border class="layout-table" @selection-change="selectionChangeHandle">
			<el-table-column prop="id" label="序号" header-align="center" align="center"></el-table-column>
			<el-table-column prop="permmenu" label="权限菜单" header-align="center" align="center"></el-table-column>
			<el-table-column prop="name" label="权限名称" header-align="center" align="center"></el-table-column>
			<el-table-column prop="describe" label="权限说明" header-align="center" align="center" width="180"></el-table-column>
			<el-table-column prop="status" label="状态" header-align="center" align="center"></el-table-column>
			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="200">
				<template #default="scope">
					<el-button type="primary" link @click="updatePermHandle(false, scope.row)">修改</el-button>
					<el-button type="primary" link @click="deleteRecord(scope.row)">删除</el-button>
					<el-button type="primary" link @click="closeRecord(scope.row)">关闭</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination
			:current-page="state.pageNum"
			:page-size="state.pageSize"
			:total="state.total"
			layout="total, sizes, prev, pager, next, jumper"
			@size-change="sizeChangeHandle"
			@current-change="currentChangeHandle"
		>
		</el-pagination>

		<!-- 新增/修改 -->
		<updatePermDialog ref="updatePermRef"></updatePermDialog>
	</el-card>
</template>

<script setup lang="ts" name="SysRoleIndex">
import { reactive, ref, onMounted } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'

import updatePermDialog from './components/updatePermDialog.vue'

interface IListDataType {
	// 列表数据项
	id: Number
	permmenu: string
	name: string
	describe: string
	status: string
}

const state = reactive({
	queryForm: {
		state: '',
		status: ''
	},
	pageNum: 1,
	pageSize: 10,
	total: 1,
	dataListLoading: false
})
const dataList = ref<IListDataType[]>([
	{ id: 1, name: '标准申报审核', permmenu: '列表审核——主管单位', status: '正常', describe: '系统管理员' },
	{ id: 2, name: '住建局审核', permmenu: '列表审核——住建委审核', status: '正常', describe: '系统管理员' }
]) // 列表数据

const showUpdateRoleDialog = ref<boolean>(false)
const showUpdatePermDialog = ref<boolean>(false)

const reset = () => {}

const selectionChangeHandle = () => {}
const currentChangeHandle = () => {}
const sizeChangeHandle = () => {}
const getDataList = () => {}

// role操作
const updatePermRef = ref()
const updatePermHandle = (isUpdate: Boolean, row: any) => {
	// true 新增  false 修改
	updatePermRef.value.init(isUpdate, row)
}

// 删除
const deleteRecord = () => {
	ElMessageBox.confirm('是否删除?', '提示', {
		confirmButtonText: '确认',
		cancelButtonText: '取消',
		type: 'warning'
	})
		.then(() => {
			ElMessage({
				type: 'success',
				message: '删除成功'
			})
		})
		.catch(() => {
			ElMessage({
				type: 'info',
				message: '删除失败'
			})
		})
}

// 关闭
const closeRecord = () => {
	ElMessageBox.confirm('是否关闭?', '提示', {
		confirmButtonText: '确认',
		cancelButtonText: '取消',
		type: 'warning'
	})
		.then(() => {
			ElMessage({
				type: 'success',
				message: '关闭成功'
			})
		})
		.catch(() => {
			ElMessage({
				type: 'info',
				message: '关闭失败'
			})
		})
}

onMounted(() => {
	// getDataList()
})
</script>

<style scoped>
.el-dropdown-link {
  display: flex;
  align-items: center;
  line-height: normal;
  margin-left: 10px;
}
</style>
